<template>
  <section class="content">
    <div class="box box-info">
      <div class="box-header with-border p-tb-n">
        <h3 class="box-title">仓库调拨</h3>
      </div>
      <div class="box-body">
        <div class="form-horizontal">
          <div class="clearfix row">
            <div class="col-sm-12 flex" style="align-items: initial">
              <label class="control-label bg-gray min-width">调出仓位置：</label>
              <div class="inline-block">
                <div class="m-b-20" v-if="userPrivilegeStock.length == 0">
                  <label class="payment">
                    <i class="fa fa-warning"></i>
                    您当前还未添加仓库
                    <router-link to="/v1/goods/category/getList" class="text-red text-bold">【立即添加】</router-link>
                  </label>
                </div>
                <div v-else>
                  <button type="button"
                          class="btn btn-default btn-flat m-r-10 m-b-20" :class='[{ "btn-info" :-1==activeAllocateWh}]'
                          @click="chooseTransferWh(null,-1)">全部
                  </button>
                  <button type="button" v-for="(userPrivilegeStockItem,index) in userPrivilegeStock"
                          class="btn btn-default btn-flat m-r-10 m-b-20"
                          :class='[{ "btn-info" :index==activeAllocateWh}]'
                          @click="chooseTransferWh(userPrivilegeStockItem.id,index)">{{userPrivilegeStockItem.name}}
                  </button>
                </div>
                <!--<button type="button" class="btn btn-default btn-flat m-r-10 pull-left"-->
                        <!--@click="chooseTransferWh(null,-1)"-->
                        <!--:class='[{ "btn-info" :activeAllocateWh == -1}]'>全部-->
                <!--</button>-->
                <!--<button v-for="(userPrivilegeStockItem, index) in userPrivilegeStock" type="button"-->
                        <!--class="btn btn-default btn-flat m-r-10  m-b-20"-->
                        <!--:class='[{ "btn-info" :index==activeAllocateWh}]'-->
                        <!--@click="chooseTransferWh(userPrivilegeStockItem.id,index)">{{userPrivilegeStockItem.name}}-->
                <!--</button>-->
              </div>
            </div>
          </div>
          <div class="clearfix row">
            <div class="col-sm-12 flex" style="align-items: initial">
              <label class="control-label bg-gray min-width">调拨状态：</label>
              <div class="inline-block">
                <button v-for="(allocateStateItem, index) in allocateState" type="button"
                        class="btn btn-default btn-flat m-r-10 m-b-20"
                        :class='[{ "btn-info" :index==activeAllocateState}]'
                        @click="chooseTransferStatus(index,allocateStateItem.status)">{{allocateStateItem.name}}
                </button>
              </div>
            </div>
          </div>
          <div class="form-group">
            <div class="col-sm-12 flex">
              <label class="control-label bg-gray min-width">输入搜索：</label>
              <div class="inline-block">
                <input v-model.trim="allocationParam.num" style="width: 387.5px;" type="text"
                       class="form-control pull-left" placeholder="请输入调拨单号">
                <button v-if="$_has('sys:whAllot:list')" class="btn bg-green m-lr-10"
                        @click="searchAllocationNum(allocationParam.num)">搜索
                </button>
                <button class="btn btn-danger m-lr-10" @click="reset">重置</button>
              </div>
            </div>
          </div>
        </div>
        <!-- /.box-body -->

        <!-- /.box-footer -->
      </div>
    </div>
    <div class="row">
      <div class="col-xs-12">
        <div class="box box-info">
          <div class="box-header with-border">
            <h3 class="box-title">数据列表</h3>
            <!--<button type="button" class="btn btn-success pull-right m-r-10" @click="printAllocate">打印调拨单</button>-->
            <!--<button v-if="$_has('sys:whAllot:in')" type="button" class="btn btn-success pull-right m-r-10" @click="exportInfo">导出</button>-->
            <!--<button v-if="$_has('sys:whAllot:out')" type="button" class="btn btn-success pull-right m-r-10" @click="exportInfo">导入</button>-->
            <button type="button" class="btn btn-primary pull-right m-r-10" data-toggle="modal"
                    data-target="#modal-default" @click="createTransferFn()" v-if="$_has('sys:whAllot:add')">创建调拨单
            </button>
          </div>
          <!-- /.box-header -->
          <div class="box-body">
            <table id="example3" class="table table-bordered table-striped dataTable">
              <div class="overlay" v-if="show">
                <i class="fa fa-refresh fa-spin"></i>
              </div>
              <thead>
              <tr>
                <!--<th>-->
                  <!--<label>-->
                    <!--<input type="checkbox" v-model='checked' @click='checkedAll'>-->
                  <!--</label>-->
                <!--</th>-->
                <th>调拨单编号</th>
                <th>调出仓库</th>
                <th>调入仓库</th>
                <th>运单号</th>
                <th>创建时间</th>
                <th>状态</th>
                <th>操作</th>
              </tr>
              </thead>
              <tbody>
              <tr v-if="getAllocationList.length==0">
                <td colspan="7">暂时没有数据</td>
              </tr>
              <tr v-for="(getAllocationListItem, index) in getAllocationList" :key="index">
                <!--<td v-if="getAllocationList.length==2" colspan="getAllocationList.length">没有数据</td>-->
                <!--<td>-->
                  <!--<label>-->
                    <!--<input type="checkbox" v-model='checkList' @click="checkedItem($event)"-->
                           <!--:value="getAllocationListItem.num">-->
                  <!--</label>-->
                <!--</td>-->
                <td>{{getAllocationListItem.num}}</td>
                <td>{{getAllocationListItem.fromWhName}}</td>
                <td>{{getAllocationListItem.toWhName}}</td>
                <td>
                  {{getAllocationListItem.transportNum}}
                </td>
                <td>{{getAllocationListItem.createTime}}</td>
                <td :class="">{{inStorckStatus.get(getAllocationListItem.status)}}</td>
                <td>
                  <div class="flex">
                    <span style="flex: 1">
                      <a class="text-green" @click="editorTransfer(getAllocationListItem.num,index)" data-toggle="modal"
                         data-target="#modal-default" v-if="getAllocationListItem.status == 1 && $_has('sys:whAllot:edit')">编辑</a>
                    </span>
                    <span style="flex: 1">
                      <a @click="deleteTransferFn(getAllocationListItem.num)" class="text-green"
                         v-if="getAllocationListItem.status == 1 && $_has('sys:whAllot:del')">取消</a>
                    </span>
                    <span style="flex: 1">
                      <a class="text-green" @click="getAllotDetail(getAllocationListItem.num,index)" data-toggle="modal"
                         data-target="#modal-default" v-if="$_has('sys:whAllot:edit')">详情</a>
                    </span>
                  </div>
                </td>
              </tr>
              </tbody>
            </table>

            <div class="clearfix" v-if="getAllocationList.length!=0">
              <div class="m-t-15 pull-right">
                <pagination :total="pages.allocationList.total" :current-page='pages.allocationList.pageNum'
                            :display="pages.allocationList.display" @pagechange="pagechange"></pagination>
              </div>
            </div>
          </div>
          <!-- /.box-body -->
        </div>
        <!-- /.box -->

      </div>
      <!-- /.col -->
    </div>
    <!-- /.row -->
    <div class="modal fade" id="modal-default">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">{{modalTitle}}</h4>
          </div>
          <div class="modal-body">
            <div class="form-horizontal max_height">
              <div class="">
                <div class="form-group">
                  <div class="col-sm-6 flex">
                    <label for="" class="control-label bg-gray min-width">调出仓库：</label>
                    <div class="inline-block">
                      <div v-if="userPrivilegeStock.length == 0">
                        <label class="payment">
                          <i class="fa fa-warning"></i>
                          您当前还未添加仓库
                          <router-link to="/v1/goods/category/getList" class="text-red text-bold">【立即添加】</router-link>
                        </label>
                      </div>
                      <select v-else class="form-control" v-model="selectedStorck.fromStorck" :disabled="disabled">
                        <option value="">请选择调出仓库</option>
                        <option v-for="(userPrivilegeStockItem,index) in userPrivilegeStock"
                                :value="userPrivilegeStockItem.id">{{userPrivilegeStockItem.name}}
                        </option>
                      </select>
                    </div>
                  </div>
                  <div class="col-sm-6 flex">
                    <label for="" class="control-label bg-gray min-width">调入仓库：</label>
                    <div class="inline-block">
                      <div v-if="inStorckList.length == 0">
                        <label class="payment">
                          <i class="fa fa-warning"></i>
                          您当前还未添加仓库
                          <router-link to="/v1/goods/category/getList" class="text-red text-bold">【立即添加】</router-link>
                        </label>
                      </div>
                      <select v-else class="form-control" v-model="selectedStorck.inStorck" :disabled="disabled">
                        <option value="">请选择调入仓库</option>
                        <option v-for="(userPrivilegeStockItem,index) in inStorckList"
                                :value="userPrivilegeStockItem.id">{{userPrivilegeStockItem.name}}
                        </option>
                      </select>
                    </div>
                  </div>
                </div>
                <div class="form-group">
                  <div class="col-sm-6 flex">
                    <label for="" class="control-label bg-gray min-width">运费：</label>
                    <div class="inline-block">
                      <input type="text" class="form-control" :disabled="disabled" v-model="selectedStorck.transMoney"
                             placeholder="可不填写">
                    </div>
                  </div>
                </div>
                <div class="form-group">
                  <label for="" class="col-sm-12">
                    <a v-show="isReadonly" class="btn btn-primary pull-left m-r-10"
                       @click="addProduct(0)">添加产品</a>
                  </label>
                </div>

                <div v-if="whAllotListVOList.length !== 0" class="form-group">
                  <div class="col-sm-12">
                    <table id="example4" class="table table-bordered table-hover marginNonde">
                      <thead>
                      <tr>
                        <th>商品图片</th>
                        <th>商品信息</th>
                        <th>可用库存</th>
                        <th>调拨数量</th>
                        <th>操作</th>
                      </tr>
                      </thead>
                      <tbody>
                      <tr v-for="(editorTransferSubimtItem,index) in whAllotListVOList">
                        <td>
                          <div class="imgW">
                            <img v-if="editorTransferSubimtItem.goodPic" :src="editorTransferSubimtItem.goodPic" alt="">
                            <img v-else src="@/assets/noPic.png" alt="">
                          </div>
                        </td>
                        <td>
                          <label class="m-l-15">
                            <p>
                              <label>商品编码：</label>
                              <span>{{editorTransferSubimtItem.sku}}</span>
                            </p>
                            <p>
                              <label>商品名称：</label>
                              <span>{{editorTransferSubimtItem.goodName}}</span>
                            </p>
                            <p>
                              <label>品牌名称：</label>
                              <span>{{editorTransferSubimtItem.brandName}}</span>
                            </p>
                          </label>
                        </td>
                        <td>{{editorTransferSubimtItem.countStock}}</td>
                        <td>
                          <input type="text" v-model="editorTransferSubimtItem.qty" :disabled="disabled"
                                 class="form-control"
                                 v-on:input="print($event)"
                                 style="width: 120px;display: inline-block;">
                        </td>
                        <td>
                          <a v-if="!isReadonly" href="javascript:;" class="text-green"
                             @click="deleteTransfer(editorTransferSubimtItem.id,index)" data-toggle="modal"
                             data-target="#accredit">删除</a>
                          <a v-else href="javascript:;" class="text-green">删除</a>
                        </td>
                      </tr>
                      </tbody>
                    </table>
                  </div>
                </div>
                <div class="form-group">
                  <div class="col-sm-12">
                    <textarea :disabled="disabled" class="form-control" rows="5" v-model="selectedStorck.note"
                              placeholder="备注"></textarea>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-primary" @click="submitTransferFn()">保存</button>
            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
          </div>
        </div>
        <!-- /.modal-content -->
      </div>
      <!-- /.modal-dialog -->
    </div>

    <div class="modal fade" id="modal-default1">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">选择商品</h4>
          </div>
          <div class="modal-body">
            <div class="form-horizontal">
              <div class="clearfix">
                <div class="">
                  <div class="col-sm-12 flex">
                    <label for="" class="min-width control-label">输入搜索：</label>
                    <div class="inline-block">
                      <input v-model.trim="choosesku" type="text" class="form-control pull-left" style="width: 45%" placeholder="请输入货号">
                      <button class="btn bg-green pull-left m-lr-10" @click="searchProduct">搜&nbsp;索</button>
                      <button class="btn btn-danger pull-left m-lr-10" @click="resetProduct">重&nbsp;置</button>
                    </div>
                  </div>
                </div>
                <div class="form-group">
                  <label for="" class="col-sm-12">
                    <!--<button type="button" class="btn btn-success pull-left m-r-10" data-toggle="modal" data-target="#modal-default">创建调拨单</button>-->
                  </label>
                </div>
                <div class="">
                  <div class="col-sm-12">
                    <table id="example5" class="table table-bordered table-hover marginNonde">
                      <!--<div class="overlay" v-if="show">-->
                        <!--<i class="fa fa-refresh fa-spin"></i>-->
                      <!--</div>-->
                      <thead>
                      <tr>
                        <th>
                          <label>
                            <!--<input type="checkbox" class="flat-red">-->
                          </label>
                        </th>
                        <th style="width: 13%">商品图片</th>
                        <th>商品信息</th>
                        <th>可用库存</th>
                      </tr>
                      </thead>
                      <tbody>
                      <tr v-if="addProductList.length == 0">
                        <td colspan="4">
                          没有数据
                        </td>
                      </tr>
                      <tr v-else v-for="(addProductListItem, index) in addProductList">
                        <td>
                          <label>
                            <input type="checkbox" class="flat-red" :value="addProductListItem"
                                   v-model="checkedProduct">
                          </label>
                        </td>
                        <td class="text-center">
                          <img v-if="addProductListItem.goodsPic" :src="addProductListItem.goodsPic" alt="">
                          <img v-else src="@/assets/noPic.png" alt="">
                        </td>
                        <td class="text-left" style="padding-left: 20px;">
                          <label class="m-l-15">
                            <p>
                              <label>商品编码：</label>
                              <span>{{addProductListItem.sku}}</span>
                            </p>
                            <p>
                              <label>商品名称：</label>
                              <span>{{addProductListItem.goodsName}}</span>
                            </p>
                            <p>
                              <label>品牌名称：</label>
                              <span>{{addProductListItem.brandName}}</span>
                            </p>
                          </label>
                        </td>
                        <td>
                          {{addProductListItem.countStock}}
                        </td>
                      </tr>
                      </tbody>
                    </table>
                    <div class="clearfix"  v-if="addProductList.length != 0">
                      <div class="m-t-15 pull-right">
                        <pagination :total="inventory.total" :current-page='inventory.pageNum'
                                    :display="inventory.dispaly"
                                    @pagechange="pagechange1"></pagination>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-primary"  @click="addProductSubmit()">保存</button>
            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
          </div>
        </div>
        <!-- /.modal-content -->
      </div>
      <!-- /.modal-dialog -->
    </div>

    <div class="modal fade" id="accredit">
      <div class="modal-dialog" style="width: 400px;">
        <div class="modal-content">
          <div class="modal-header" style="background: #FFF;">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">确认信息</h4>
          </div>
          <div class="modal-body">
            <p>{{notarize}}</p>
          </div>
          <div class="modal-footer">
            <button v-if="usPpout" type="button" class="btn btn-default pull-left" data-dismiss="modal"
                    @click="notarizeFn">是
            </button>
            <button v-else type="button" class="btn btn-default pull-left" data-dismiss="modal" @click="notarizeFn">是
            </button>
            <button type="button" class="btn btn-primary" data-dismiss="modal">否</button>
          </div>
        </div>
        <!-- /.modal-content -->
      </div>
      <!-- /.modal-dialog -->
    </div>

    <transition name="fade">
      <div v-if="errorShow" class="gritter-notice-wrapper " :class="{'success-notice-wrapper':errorClass}">
        <div id="gritter-item-4" class="gritter-item-wrapper gritter-error" style="" role="alert">
          <div class="gritter-item"><a class="gritter-close" tabindex="1" @click="closeError"><i
            class="fa fa-close"></i></a>
            <div class="gritter-without-image"><span class="gritter-title">{{errorTitle}}</span>
              <p>{{errorMsg}}</p></div>
          </div>
        </div>
      </div>
    </transition>
  </section>
</template>


<script>
  import instance from '@/api/index.js'
  import pagination from '@/components/common/pageComponent'

  export default {
    name: "stroageAllot",
    data() {
      return {
        activeAllocateWh: -1,//调出仓库位置addClass样式
        allocateState: [{name: '全部', status: null}, {name: '待出库', status: "1"}, {name: '待入库', status: "2"}, {
          name: '已完成',
          status: "3"
        }, {name: '已取消', status: "0"}],//调拨状态
        activeAllocateState: 0,//调拨状态addClass样式
        status: "",//调拨状态
        show: false,//loading加载
        checked: false,
        checkList: [],//全选/反选获取的id
        allocationParam: {},//提交时传递的值
        getAllocationList: [],//获取调拨单列表
        rowsAllotList: [],//获取行数据
        addProductList: [],//获取添加产品列表
        inStorckList: [],//获取调入仓库列表
        inStorckStatus: new Map,
        editorTransferparam: {},//编辑传递的值
        editorTransferSubimt: {},
        whAllotListVOList: [],//编辑保存
        seavEditorTransfer: [],//保存编辑行数据的数据
        createTransfer: {},//创建调拨单
        whAllotLists: [],//调拨单明细对象
        qty: [],//调拨数量
        userPrivilegeStock: [],//获取用户可查看仓库
        userPrivilegeStockFilter:[],//过滤获取用户可查看仓库
        checkedProduct: [],//选择产品checkbox
        checkedProductList: [],//选择产品列表
        saveCheckedProductList: [],//存储选择产品列表
        selectedStorck: {//选择调出仓库
          fromStorck: "",//调出仓库
          inStorck: "",//调入仓库
          transMoney: 0,//运费
          transportNum: 0,//运单号
          note: "",//备注
        },
        analysisType: {
          transferStatus: ["已取消", "待出库", "待入库", "已完成"]
        },//解析状态码

        modalTitle: "创建调拨单",//创建和编辑弹窗口标题
        disabled: false,
        isReadonly: false,
        pages: {
          allocationList: {
            total: 0,
            pageNum: 1,
            display: 10
          },
          productList: {
            total: 0,
            pageNum: 1,
            display: 5
          },

        },//分页
        inventory: {
          total: 0,
          pageNum: 1,
          dispaly: 1
        },
        saveEditorTransfer: {
          num: null
        },
        clickTag: false,//修改运单号
        isReadonly: false,//备注

        usPpout: false,//弹框
        notarize: '',//确认信息

        errorShow: false,//错误显示
        errorMsg: '',//错误信息
        errorTitle: '',//错误提示标题
        errorClass: false,//错误样式
        chooseProParmas:{},
        choosesku:'',
      }
    },
    methods: {
      //消息弹窗提示
      alertMessage: function (value) {
        if (value) {
          this.$message({
            showClose: false,
            message: '操作成功!',
            type: 'success'
          });
        } else {
          this.$message({
            showClose: false,
            message: '操作失败!',
            type: 'error'
          });
        }
      },
      // 获取分页
      pagechange: function (currentPage) {
        this.allocationParam.page = currentPage;
        this.pages.allocationList.pageNum = currentPage;
        this.getAllocationListFn();
      },
      pagechange1: function (currentPage) {
        this.inventory.pageNum = currentPage;
        this.chooseProParmas.page = currentPage;
        this.addProduct();
      },

      //获取调拨单列表
      getAllocationListFn: function () {
        let vm = this;
        vm.allocationParam.rows = 10;
        vm.pages.allocationList.display = vm.allocationParam.rows;
        vm.show = true;
        instance.post('/v1/whReceiptProcess/getAllotList', vm.allocationParam).then(function (data) {
          vm.getAllocationList = data.data.data.list;
          vm.pages.allocationList.total = data.data.data.total;
          vm.show = false;//loading加载
          console.log(data.data.data)
        })
      },

      //获取调入仓库下拉列表
      inStorckListFn: function () {
        let vm = this;
        instance.post('/v1/warehouse/getWareHouseNoPageList').then(function (data) {
          vm.inStorckList = data.data.data;
        })
      },

      //选择调出仓库位置
      chooseTransferWh: function (fromWh, index) {
        this.activeAllocateWh = index;
        this.allocationParam.fromWh = fromWh;
        this.getAllocationListFn();
      },

      //选择调拨状态
      chooseTransferStatus: function (index, status) {
        this.activeAllocateState = index;
        this.allocationParam.status = status;
        this.getAllocationListFn();
      },

      // 搜索调拨单号
      searchAllocationNum: function (e) {
        this.editorTransferparam.enterpriseId = "1";
        this.allocationParam.num = e;
        this.allocationParam.status = null;
        this.allocationParam.fromWh = "";
        this.getAllocationListFn();
      },

      //重置
      reset: function () {
        this.activeAllocateState = 0;
        this.allocationParam.status = null;
        this.activeAllocateWh = -1;
        this.allocationParam.fromWh = null;
        this.allocationParam.num = null;
        this.getAllocationListFn();
      },

      //获取用户可查看仓库
      userPrivilegeStockFn: function () {
        let vm = this;
        instance.post('/v1/warehouse/getUserWareHouseList').then(function (data) {
          vm.userPrivilegeStock = data.data.data;
          // vm.getAllocationListFn(vm.allocationParam.pages)
        })
      },

      //调拨单行数据编辑
      editorTransfer: function (num) {
        let vm = this;
        vm.isReadonly = true;
        vm.saveEditorTransfer.num = num;
        vm.modalTitle = '编辑调拨单';
        instance.post('/v1/whReceiptProcess/getAllotDetail', {num: num}).then(function (data) {
          vm.editorTransferSubimt = data.data.data;
          vm.whAllotListVOList = data.data.data.whAllotListVOList;
          vm.selectedStorck.fromStorck = vm.editorTransferSubimt.fromWh;
          vm.selectedStorck.inStorck = vm.editorTransferSubimt.toWh;
          vm.selectedStorck.transMoney = vm.editorTransferSubimt.tranMoney;
          vm.selectedStorck.note = vm.editorTransferSubimt.note;
          console.log(data)
        })
      },

      getAllotDetail: function (num) {
        let vm = this;
        vm.disabled = true;
        vm.isReadonly = false;
        vm.saveEditorTransfer.num = num;
        vm.modalTitle = '调拨单详情';
        instance.post('/v1/whReceiptProcess/getAllotDetail', {num: num}).then(function (data) {
          vm.editorTransferSubimt = data.data.data;
          vm.whAllotListVOList = data.data.data.whAllotListVOList;
          vm.selectedStorck.fromStorck = vm.editorTransferSubimt.fromWh;
          vm.selectedStorck.inStorck = vm.editorTransferSubimt.toWh;
          vm.selectedStorck.transMoney = vm.editorTransferSubimt.tranMoney;
          vm.selectedStorck.note = vm.editorTransferSubimt.note;
          console.log(data)
        })
      },

      //修改运单号
      editTraNum: function () {

      },

      //添加产品
      addProduct: function (_type) {
        let vm = this;
        vm.show = true;
        if(_type == 0){
          vm.chooseProParmas.sku = '';
          vm.choosesku = '';
          vm.inventory.pageNum = 1;
        }else {
          vm.chooseProParmas.sku = vm.choosesku;
        }
        if(!vm.selectedStorck.fromStorck){
          vm.$alert('请选择调出仓', '提示', {
            confirmButtonText: '确定',
          });
          return;
        }
        $("#modal-default1").modal('show');
        this.checkedProduct = [];
        if (vm.selectedStorck.fromStorck) {
          vm.chooseProParmas.whId = vm.selectedStorck.fromStorck;
          vm.chooseProParmas.rows = 5;
          vm.inventory.dispaly = vm.chooseProParmas.rows;
          vm.chooseProParmas.page = vm.inventory.pageNum;
          console.log(vm.chooseProParmas)
          instance.post('/v1/warehouse/getStockList', vm.chooseProParmas).then(function (data) {
            if(data.data.success){
              vm.show = false;
              vm.addProductList = data.data.data.list;
              vm.inventory.total = data.data.data.total;
            }
          })
        }
      },

      //搜索产品
      searchProduct:function(){
        this.chooseProParmas.sku = this.choosesku;
        this.addProduct();
      },

      //重置
      resetProduct:function(){
        this.chooseProParmas.sku = '';
        this.choosesku = '';
        this.addProduct();
      },


      //添加产品提交
      addProductSubmit: function () {
        if(this.checkedProduct.length == 0){
          this.$alert('至少选择一个商品！', '提示', {
            confirmButtonText: '确定',
          });
          return;
        }
        for (let i = 0; i < this.checkedProduct.length; i++) {
          let checkItem = {};
          checkItem.brandName = this.checkedProduct[i].brandName;
          checkItem.sku = this.checkedProduct[i].sku;
          checkItem.goodName = this.checkedProduct[i].goodsName;
          checkItem.goodPic = this.checkedProduct[i].goodsPic;
          checkItem.goodId = this.checkedProduct[i].id;
          checkItem.qty = 0;
          let stockVOsTotal = 0;
          for (let n = 0; n < this.checkedProduct[i].stockDetail.length; n++) {
            stockVOsTotal = stockVOsTotal + parseInt(this.checkedProduct[i].stockDetail[n].qty);
          }
          checkItem.countStock = stockVOsTotal;
          let matchTag = true;
          if (this.whAllotListVOList) {
            for (let j = 0; j < this.whAllotListVOList.length; j++) {
              let currentItem = this.whAllotListVOList[j];
              if (this.checkedProduct[i].id == currentItem.goodId) {
                matchTag = false;
                break;
              }
            }
          } else {
            matchTag = true;
          }
          if (matchTag) {
            (this.whAllotListVOList).push(checkItem);
          }

        }
        $("#modal-default1").modal('hide');
        console.log(this.editorTransferSubimt)
      },

      //提交保存创建/修改调拨单
      submitTransferFn: function () {
        let postUrl = "";
        let vm = this;
        if(!vm.selectedStorck.fromStorck){
          vm.$alert('请选择调出仓', '提示', {
            confirmButtonText: '确定',
          });
          return;
        }
        if(vm.selectedStorck.fromStorck == vm.selectedStorck.inStorck){
          vm.$alert('调入仓库与调出仓库一样 请重新选择', '提示', {
            confirmButtonText: '确定',
          });
          return;
        }
        if(!vm.selectedStorck.inStorck){
          vm.$alert('请选择调入仓', '提示', {
            confirmButtonText: '确定',
          });
          return;
        }
        if(vm.whAllotListVOList.length == 0){
          vm.$alert('请添加商品！', '提示', {
            confirmButtonText: '确定',
          });
          return;
        }
        vm.createTransfer.whAllot = {
          "fromWh": vm.selectedStorck.fromStorck,
          "toWh": vm.selectedStorck.inStorck,
          "num": vm.saveEditorTransfer.num,
          "transMoney": vm.selectedStorck.transMoney,
          "note": vm.selectedStorck.note,
        };
        vm.whAllotLists = [];
        for (let i = 0; i < vm.whAllotListVOList.length; i++) {
          let transferAdd = {};
          transferAdd.qty = vm.whAllotListVOList[i].qty;
          if(vm.whAllotListVOList[i].qty == 0){
            vm.$alert('请输入商品数量！', '提示', {
              confirmButtonText: '确定',
            });
            return;
          }
          if(vm.whAllotListVOList[i].qty > vm.whAllotListVOList[i].countStock){
            vm.$alert('您输入的商品数量大于当前库存数量！', '提示', {
              confirmButtonText: '确定',
            });
            return;
          }
          transferAdd.goodId = vm.whAllotListVOList[i].goodId;
          vm.whAllotLists.push(transferAdd);
        }
        vm.createTransfer.whAllotLists = vm.whAllotLists;
        let transferNum = vm.createTransfer.whAllot.num;
        if (transferNum) {
          postUrl = '/v1/whReceiptProcess/updateAllot';
        } else {
          postUrl = '/v1/whReceiptProcess/addAllot';
        }
        ;
        console.log(vm.createTransfer)
        instance.post(postUrl, vm.createTransfer).then(function (data) {
          vm.alertMessage(data.data.success);
          $("#modal-default").modal('hide');
          vm.getAllocationListFn();
        }).catch(function (err) {
          console.log(err)
        })
        vm.qty = [];
      },

      //删除
      deleteTransfer: function (id, index) {
        this.editorTransferSubimt.splice(index, 1)
      },


      //删除调拨单
      deleteTransferFn: function (id) {
        let vm = this;
        vm.$confirm('此操作将取消此调拨单, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          instance.post('/v1/whReceiptProcess/cancelAllot/' + id).then(function (data) {
            vm.alertMessage(data.data.success);
            vm.getAllocationListFn();
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        })
        // instance.post('/v1/whReceiptProcess/deleteAllot/' + id).then(function (data) {
        //   if(data.data.success){
        //     vm.getAllocationListFn()
        //   }
        // })

      },

      //调拨数量
      print: function (e) {
        let maxNum = $(e.target).parents("tr").find("td:nth-child(2)").html();
        for (let j = 0; j < this.qty.length; j++) {
          let num = parseInt(this.qty[j]);
          if (num >= maxNum) {
            this.qty[j] = maxNum
          }
        }
      },

      //创建调拨单
      createTransferFn: function () {
        let vm = this;
        vm.disabled = false;
        vm.isReadonly = true;
        vm.saveEditorTransfer.num = null;
        vm.saveEditorTransfer.num = null;
        vm.editorTransferSubimt = [];
        vm.selectedStorck.fromStorck = '';
        vm.selectedStorck.inStorck = '';
        vm.saveEditorTransfer.num = '';
        vm.selectedStorck.transMoney = '';
        vm.selectedStorck.note = '';
        vm.whAllotListVOList = [];
        vm.modalTitle = '创建调拨单';
      },

      //全选反选
      checkedAll: function () {
        var vm = this;
        if (vm.checked) { //实现反选
          vm.checkList = [];
        } else { //实现全选
          vm.checkList = [];
          vm.getAllocationList.forEach(function (item, index) {
            if (index >= 0) {
              vm.checkList.push(item.num);
            }
          });
        }
      },

      //行数据选择框
      checkedItem: function (e) {
        this.checkList.push(e.target.value)
      },

      //导入导出
      exportInfo: function () {
        if (this.checkList.length == 0) {
          alert("请选择")
        } else {
          alert("导入导出中...")
        }
      },

      //确认信息提示
      notarizeFn: function () {
      },

      //打印调拨单
      printAllocate: function () {
        if (this.checkList.length == 0) {
          alert("请选择")
        } else {
          alert("导入导出中...")
        }
      },
    },
    created() {
      this.inStorckStatus.set("0", "已取消");
      this.inStorckStatus.set("1", "待出库");
      this.inStorckStatus.set("2", "待入库");
      this.inStorckStatus.set("3", "已完成");
      this.getAllocationListFn();
      this.userPrivilegeStockFn()
      this.inStorckListFn()
    },
    components: {
      pagination
    },
    filters: {
      whNameFilter: function (value) {
        console.log(typeof value);
        let vm = this;
        let returnWhName = "";
        for (let i = 0; i < vm.userPrivilegeStock.length; i++) {
          if (parseInt(value) == vm.userPrivilegeStock[i].id) {
            returnWhName = this.userPrivilegeStock[i].name
            return returnWhName
          }
        }
      }
    }
  }


</script>

<style scoped>
</style>
